import React, { PureComponent } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import { Card, Radio, Row, Col, Badge, Button } from 'antd';
import CustomCard from './Components/CustomCard'
import PieChart from './Components/PieChart'
import BarChart from './Components/BarChart'
import Table from './Components/Table';
import styles from './index.less';
import { studentAnalyze } from '@/services/studentAnalyze'
const timeList = [
    { name: '特种设备安全管理', time: 30 },
    { name: '工业锅炉司炉', time: 28 },
    { name: '电站锅炉司炉', time: 32 },
    { name: '锅炉水处理', time: 32 },
    { name: '快开门式压力容器', time: 24 },
    { name: '移动式压力容器充装', time: 24 },
    { name: '氧舱维护保养', time: 24 },
    { name: '气瓶充装', time: 24 },
    { name: '电梯修理', time: 32 },
    { name: '起重机械指挥', time: 24 },
    { name: '起重机司机', time: 24 },
    { name: '客运索道修理', time: 28 },
    { name: '客运索道司机', time: 24 },
    { name: '大型游乐设施修理', time: 28 },
    { name: '大型游乐设施操作', time: 24 },
    { name: '叉车司机', time: 24 },
    { name: '观光车和观光列车司机', time: 24 },
    { name: '安全阀校验', time: 32 },
    { name: '金属焊工操作', time: 32 },
    { name: '非金属焊接操作', time: 32 }
]

class Print extends PureComponent<any, any> {
    printHandle = () => {
        //判断iframe是否存在，不存在则创建iframe
        let iframe = document.getElementById("print-iframe");
        if (!iframe) {
            let el = document.getElementById("table");
            iframe = document.createElement('IFRAME');
            let doc = null;
            iframe.setAttribute("id", "print-iframe");
            iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
            document.body.appendChild(iframe);
            doc = iframe.contentWindow.document;
            doc.write('<div>' + el.innerHTML + '</div>');
            doc.close();
            iframe.contentWindow.focus();
        }
        iframe.contentWindow.print();
        if (navigator.userAgent.indexOf("MSIE") > 0) {
            document.body.removeChild(iframe);
        }
    }
    render() {
        const duration = sessionStorage.getItem('duration')
        const subjects = sessionStorage.getItem('subjects')
        return (
            <PageContainer>
                <Card>
                <Table subjects={subjects} duration={duration} />
                <Button onClick={this.printHandle} style={{margin:'30px auto',display:'block'}} type="primary">立即打印</Button>
                </Card>
            </PageContainer>
        );
    }
}

export default Print;
